// 题目链接：https://www.luogu.com.cn/problem/P1102

#include <iostream>
#include <algorithm>

using namespace std;

const int N = 200010;
int n, c;
int arr[N];

// 二分法
int binary_search1(int arr[], int len, int x)
{
    int left = -1;
    int right = len;
    int mid;

    while (left + 1 < right)
    {
        mid = (left + right) / 2;

        if (arr[mid] < x)
            left = mid;
        else
            right = mid;
    }

    if (arr[right] != x)
        return -1;
    else
        return right;
}

int binary_search2(int arr[], int len, int x)
{
    int left = -1;
    int right = len;
    int mid;

    while (left + 1 < right)
    {
        mid = (left + right) / 2;

        if (arr[mid] <= x)
            left = mid;
        else
            right = mid;
    }

    if (arr[left] != x)
        return -1;
    else
        return left;
}

int main()
{
    int A, B, res1, res2;
    long long cnt = 0; // 要用long long
    scanf("%d %d", &n, &c);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &arr[i]);
    }

    // 将数组变成有序数组
    sort(arr, arr + n);

    // A - B = C  -->  A - C = B
    for (int i = 0; i < n; ++i)
    {
        A = arr[i];
        B = arr[i] - c;

        // res1左边都是小于B的数
        res1 = binary_search1(arr, n, B);
        if (res1 == -1)
            continue;

        // res2开始都是大于B的数
        res2 = binary_search2(arr, n, B);

        // res2 - res1 + 1 = 数值为B的数的个数
        cnt += (res2 - res1 + 1);
    }
    printf("%lld\n", cnt);

    return 0;
}

//-------------------------------------------------------------
// 双指针法
#include <iostream>
#include <algorithm>

using namespace std;

const int N = 200010;
int n, c;
int arr[N];

//  双指针法
int main()
{
    scanf("%d %d", &n, &c);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &arr[i]);
    }
    // 将数组变为有序数组
    sort(arr, arr + n);

    int fast = 0, slow = 0;                        // 快慢指针
    int fast_next, slow_next;                      // 下一个不等于arr[fast]和arr[slow]的位置
    long long cnt = 0, fast_num = 0, slow_num = 0; // 一定要用long long!!!
    while (fast < n)
    { // 遍历整个数组
        int ret = arr[fast] - arr[slow];
        if (ret < c)
        { // 如果ret小于c，则让fast指针往后走，使得ret变大
            ++fast;
        }
        else if (ret > c)
        { // 如果ret大于c，则让slow指针往后走，使得ret变小
            ++slow;
        }
        else
        {
            // 找到下一个不等于arr[fast]的数
            fast_next = fast;
            while ((arr[fast_next] == arr[fast]) && (fast_next < n))
                ++fast_next;
            // 找到下一个不等于arr[slow]的数
            slow_next = slow;
            while ((arr[slow_next] == arr[slow]) && (slow_next < n))
                ++slow_next;

            fast_num = fast_next - fast;  // 等于arr[fast]的数的个数
            slow_num = slow_next - slow;  // 等于arr[slow]的数的个数
            cnt += (fast_num * slow_num); // 相乘的得到A-B=C的数对的个数
            // 迭代
            slow = slow_next;
            fast = fast_next;
        }
    }
    printf("%lld", cnt);

    return 0;
}